var a = require("../../utils/config.js");

Page({
    data: {
        serviceProviderList: [],
        bankList: [ "中国银行", "中国工商银行", "中国建设银行", "中国农业银行", "中国邮政储蓄银行", "交通银行", "招商银行", "光大银行", "民生银行", "中信银行", "兴业银行", "上海浦东发展银行", "平安银行", "其他" ],
        editInputValue: "",
        isShowModal: !1,
        isShowModal2: !1,
        bankNo: "",
        serviceProviderName: "",
        bankName: "",
        serviceProviderId: "",
        bankId: "",
        bankSource: []
    },
    onLoad: function(a) {
        for (var e = this, t = wx.getStorageSync("serviceProviders"), n = [], o = 0; o < t.length; o++) n.push(t[o].name);
        e.setData({
            serviceProviderList: n,
            serviceProviderId: wx.getStorageSync("serviceProviderId"),
            serviceProviderName: wx.getStorageSync("serviceProviderName")
        }), e.loadBankSource();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    editInput: function(a) {
        this.setData({
            isShowModal: !0,
            editInputValue: ""
        });
    },
    editInput2: function(a) {
        this.setData({
            isShowModal2: !0
        });
    },
    getInput: function(a) {
        this.setData({
            editInputValue: a.detail.value
        });
    },
    getInput2: function(a) {
        this.setData({
            bankName: a.detail.value
        });
    },
    cancel: function() {
        this.setData({
            isShowModal: !1,
            isShowModal2: !1
        });
    },
    confirm: function() {
        var a = this;
        a.setData({
            isShowModal: !1,
            bankNo: a.data.editInputValue
        });
    },
    confirm2: function() {
        this.setData({
            isShowModal2: !1
        });
    },
    selectedServiceProvider: function(a) {
        var e = wx.getStorageSync("serviceProviders"), t = this;
        t.setData({
            serviceProviderName: e[a.detail.value].name,
            serviceProviderId: e[a.detail.value].id
        });
        for (var n = 0; n < t.data.bankSource.length; n++) {
            if (t.data.bankSource[n].serviceProviderId == t.data.serviceProviderId) {
                t.setData({
                    bankName: t.data.bankSource[n].bank,
                    bankNo: t.data.bankSource[n].bankNo,
                    bankId: t.data.bankSource[n].id
                });
                break;
            }
            t.setData({
                bankName: "",
                bankNo: ""
            });
        }
    },
    selectedBankName: function(a) {
        var e = this;
        e.setData({
            bankName: e.data.bankList[a.detail.value]
        });
    },
    loadBankSource: function() {
        var e = this, t = wx.getStorageSync("userId");
        wx.request({
            url: a.urlList.API_USER_GET_BANK_LIST,
            method: "GET",
            header: {
                contentType: "application/json"
            },
            data: {
                userId: t
            },
            success: function(a) {
                if (200 == a.data.status) {
                    e.setData({
                        bankSource: a.data.data
                    });
                    for (var t = 0; t < a.data.data.length; t++) a.data.data[t].serviceProviderId == e.data.serviceProviderId && e.setData({
                        bankName: a.data.data[t].bank,
                        bankNo: a.data.data[t].bankNo,
                        bankId: a.data.data[t].id
                    });
                }
            }
        });
    },
    apply: function() {
        var e = this;
        if (e.data.bankName) if (e.data.bankNo) {
            var t = {
                userId: wx.getStorageSync("userId"),
                bank: e.data.bankName,
                bankNo: e.data.bankNo,
                serviceProviderId: e.data.serviceProviderId,
                id: e.data.bankId
            };
            wx.showLoading({
                mask: !0
            }), wx.request({
                url: a.urlList.API_USER_EDIT_BANK,
                method: "POST",
                header: {
                    contentType: "application/json"
                },
                data: t,
                success: function(a) {
                    wx.hideLoading(), 200 == a.data.status ? (wx.showToast({
                        title: "提交成功"
                    }), e.loadBankSource()) : wx.showToast({
                        title: a.data.message,
                        icon: "none"
                    });
                }
            });
        } else wx.showToast({
            title: "请输入银行账号",
            icon: "none"
        }); else wx.showToast({
            title: "请输入开户银行分行和支行",
            icon: "none"
        });
    }
});